package com.person.link.service.impl;

import java.util.Date;
import java.util.List;

import com.person.commons.utils.DAO;
import com.person.commons.utils.FlipPageInfo;
import com.person.link.model.Link;
import com.person.link.service.LinkService;
import com.person.title.model.TitleFunc;




public class LinkServiceImpl implements LinkService{
	
	private DAO dao;
	

	public DAO getDao() {
		return dao;
	}

	public void setDao(DAO dao) {
		this.dao = dao;
	}
	/**
	 * 增加用户
	 * @return
	 */
	public String linkCerate(){
		
		return null;
	}
	/**
	 * 通过ID查找链接对象
	 */
	public Link findLinkByLinkId(String linkId){
		List ul=dao.find("from Link where linkId='"+linkId+"'");
		if(ul!=null&&ul.size()>=1)
			{
			return (Link) ul.get(0);
			}
		return new Link();
	}
	/**
	 * 保存Link对象
	 */
	public void addLink(Link link){
		
		dao.save(link);
	}
	/**
	 * 查找Link对象，分页列表
	 */
	public FlipPageInfo findAllLink(FlipPageInfo fpi) {
		return dao.findWithPaging("select n.linkType,n.userDate,n.linkName,n.userId,n.linkUrl," +
				"n.linkIntro,n.linkId,u.userName,t.funcName,n.linkFlag from Link n,BaseUser u,TitleFunc t " +
				"where n.userId = u.userId and t.funcId = n.funcId order by n.funcId,n.linkType,n.userDate desc", fpi);
	}
	/**
	 * 修改链接对象
	 */
	public void updateLink (Link link){
		dao.update(link);
	}
	/**
	 * 删除链接对象
	 */
	public void deleteLink(Link link){
		dao.delete(link);
	}
	/**
	 * 根据条件查询Link对象,分页列表
	 */
	public FlipPageInfo findLinkByInfo(String hql ,FlipPageInfo fpi){
		return dao.findWithPaging(hql, fpi);
	}
	/**
	 * 根据funcId从栏目功能表TitleFunc查找功能名
	 */
	public TitleFunc findTitleFuncByFuncId(String funcId){
		try{
			return (TitleFunc) dao.find(TitleFunc.class, funcId);
		}catch(Exception e){
			System.out.println("栏目功能表TitleFunc查找功能名出现异常");
		}
		return new TitleFunc();
	}

	/**
	 * 根据funcId查找Link
	 */
	public List<Link> findLinkByFuncId(String funcId) {
		
		return this.dao.find("from Link where funcId='"+funcId+"' and linkFlag='0' order by userDate desc");
	}
}